package com.sgg.springbootsgg001demo;

import com.alibaba.druid.FastsqlException;
import com.sgg.springbootsgg001demo.bean.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class SpringBootSgg001DemoApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SpringBootSgg001DemoApplication.class, args);
        // 遍历所有的bean
//        String[] beans = context.getBeanDefinitionNames();
//        for (String bean : beans) {
//            System.out.println("bean = " + bean);
//        }


        // 遍历User类型的Bean有几个，@Bean注解默认是单例的
//        String[] beanNamesForType = context.getBeanNamesForType(User.class);
//        for (String bean : beanNamesForType) {
//            System.out.println("bean = " + bean);
//        }
//
//        // 判断是单实例还是多实例
//        User user1 = context.getBean(User.class);
//        User user2 = context.getBean(User.class);
//
//
//        System.out.println(user1 == user2);
//
//        String[] beanNamesForType = context.getBeanNamesForType(FastsqlException.class);
//        for (String s : beanNamesForType) {
//            System.out.println("FastsqlException = " + s);
//        }
//
//        String[] beanNamesForType1 = context.getBeanNamesForType(Cat.class);
//        for (String s : beanNamesForType1) {
//            System.out.println("Cat = " + s);
//        }
//
//        String[] beanNamesForType2 = context.getBeanNamesForType(Dog.class);
//        for (String s : beanNamesForType2) {
//            System.out.println("Dog = " + s);
//        }
//
//        String[] beanNamesForType3 = context.getBeanNamesForType(User.class);
//        for (String s : beanNamesForType3) {
//            System.out.println("User = " + s);
//        }
//
//
//        Pig pig = context.getBean(Pig.class);
//        System.out.println("pig = " + pig);
 

//        Sheep sheep = context.getBean(Sheep.class);
//        System.out.println("sheep = " + sheep);

        Person person = context.getBean(Person.class);
        System.out.println("person = " + person);
    }
}
